home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / DCIR1.C < prev    next >
Text File  |  1993-06-10  |  5KB  |  156 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 06-04-93 (03:51)             Number: 8
  4. From: PEDRO DORIA MEUNIER          Refer#: NONE
  5.   To: DAVID NUGENT                  Recvd: NO  
  6. Subj: MOV -> XOR            1/2      Conf: (37) C++ Langua
  7. ---------------------------------------------------------------------------
  8. DN>Why not simply write the function in assembler and call it from your C++ code
  9.  
  10. Hope this helps you.
  11.  
  12. It is assumed you know how to plot a point in graphics mode using assembly.
  13. It is also assumed that if you intend to use this code fragment in C you
  14. know how to manipulate inline assembly and/or making the necessary steps
  15. to making this an PUBLIC procedure and to specify the following variables
  16. as EXTERNALs.
  17.  
  18. It uses the variables X, Y, Cw, Ck, Cradius
  19.  
  20. The Set_Pixel_XOR function first gets the screen contents at x,y coordinates
  21. and then XORs it with the new contents
  22.  
  23. If you like me to send it please say so 'cause this message is ALREADY TOO
  24. LONG...
  25.  
  26.                         Fellow Sysops, forgive me!...
  27.  
  28.  Hope to hear from you soon,
  29.  
  30.                                         Pedro Doria
  31.  
  32.  
  33. ;***************************************************************************
  34. DrawCircle      PROC    FAR                                               ;*
  35. ; Input : Cw                                                               *
  36. ;         Ck (Cw and Ck being x,y coordinates of the center)               *
  37. ;         Cradius                                                          *
  38. ;                       Written by Pedro Doria Meunier (c) 1993            *
  39. ;                                                                          *
  40. ;                                                                          *
  41. ;                       It uses the Bresenham Algoritm                     *
  42. ;***************************************************************************
  43.  
  44. CStep1:
  45.         mov     X, 0
  46.         mov     ax, Cradius
  47.         mov     Y, ax
  48.  
  49.         mov     ax, Y
  50.         mov     bl, 2
  51.         mul     bl
  52.         mov     bx, 3
  53.         sub     bx, ax
  54.         mov     Cd, bx
  55.         jmp     CStep4          ; Before all calculations we must plot
  56.                                 ; the initial points so that the circle
  57.                                 ; doesn't end up 'un'closed
  58. CStep2:
  59.         mov     cx, X
  60.         cmp     cx, Y           ; is x > y ?
  61.         jg      CircleDone
  62. CStep3:
  63.         cmp     Cd, 0
  64.         jge     CStep3_1
  65.         mov     ax, X
  66.         mov     bl, 4           ; d = d+4*x
  67.         mul     bl
  68.         add     ax, 6
  69.         add     Cd, ax
  70.         inc     X
  71.         jmp     CStep4
  72. CStep3_1:
  73.         mov     cx, X
  74.         sub     cx, Y
  75.         mov     ax, cx          ; d = d+4*(x-y)+10
  76.         mov     bl, 4
  77.         imul    bl
  78.         add     Cd, ax
  79.         add     Cd, 10
  80.         inc     X
  81.         dec     Y
  82. CStep4:
  83.         mov     cx, X
  84.         mov     dx, Y
  85.         add     cx, Cw
  86.         add     dx, Ck
  87.         cmp     XORFlag, 1
  88.         jne     SHORT CStep4_1
  89.         call    Set_Pixel_XOR
  90.         jmp     SHORT CStep4_12
  91. CStep4_1:
  92.         call    Set_PIxel       ; Plot (x+Cw, y+Ck)
  93. CStep4_12:
  94.         mov     cx, X
  95.         mov     dx, Y
  96.         add     dx, Cw
  97.         add     cx, Ck
  98.         xchg    cx, dx
  99.         cmp     XORFlag, 1
  100.         jne     SHORT CStep4_121
  101.         call    Set_Pixel_XOR
  102.         jmp     SHORT CStep4_13
  103. CStep4_121:
  104.         call    Set_Pixel       ; Plot (y+Cw, x+Ck)
  105. CStep4_13:
  106.         mov     cx, X
  107.         mov     dx, Y
  108.         neg     dx
  109.         add     dx, Cw
  110.         add     cx, Ck
  111.         xchg    cx, dx
  112.         cmp     XORFlag, 1
  113.         jne     SHORT CStep4_131
  114.         call    Set_Pixel_XOR
  115.         jmp     SHORT CStep4_14
  116. CStep4_131:
  117.         call    Set_Pixel       ; Plot (-y+Cw, x+Ck)
  118. CStep4_14:
  119.         mov     cx, X
  120.         mov     dx, Y
  121.         neg     cx
  122.         add     cx, Cw
  123.         add     dx, Ck
  124.         cmp     XORFlag, 1
  125.         jne     SHORT CStep4_141
  126.         call    Set_Pixel_XOR
  127.         jmp     SHORT CStep4_15
  128. CStep4_141:
  129.         call    Set_Pixel       ; Plot (-x+Cw, y+Ck)
  130. CStep4_15:
  131.         mov     cx, X
  132.         mov     dx, Y
  133.         neg     cx
  134.         add     cx, Cw
  135.         neg     dx
  136.         add     dx, Ck
  137.         cmp     XORFlag, 1
  138.         jne     SHORT CStep4_151
  139.         call    Set_Pixel_Xor
  140.         jmp     SHORT CStep4_16
  141. CStep4_151:
  142.         call    Set_Pixel       ; Plot (-x+Cw, -y+Ck)
  143. CStep4_16:
  144.         mov     cx, X
  145.         mov     dx, Y
  146.         neg     dx
  147.         add     dx, Cw
  148.         neg     cx
  149.         add     cx, Ck
  150.         xchg    cx, dx
  151.         cmp     XORFlag, 1
  152.         jne     SHORT CStep4_161
  153. >>> Continued to next message
  154.  
  155.  * SLMR 2.1a * MultiTask: Make twice the mistakes in ½ the time.
  156.